﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.service;
using mendian;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Media3D;
using static DXApplicationTangche.UC.订单.service.ViewSemiCheckExceptionDao;
using static DXApplicationTangche.UC.订单.service.ViewSemiCheckExceptionDao.xxx;

namespace DXApplicationTangche.UC.订单.service
{
    public class 抖音客户Service
    {
        /// <summary>
        /// 抖音客户信息
        /// </summary>
        /// <returns></returns>
        public static List<CustomerBaseInfoDTO> getCustomerBaseInfoDTOList()
        {
            return
                FunctionHelper.JsonDeserialization<List<CustomerBaseInfoDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/douyin/getCustomerBaseInfoDTOList"
                        )
                    );
        }
        /// <summary>
        /// 半成品质检逾期
        /// </summary>
        /// <returns></returns>
        public static List<ViewSemiCheckExceptionDao> getViewSemiCheckExceptionDao()
        {
            return
                FunctionHelper.JsonDeserialization<List<ViewSemiCheckExceptionDao>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/mrp_report/getViewSemiCheckExceptionAll"
                        )
                    );
        }
        public static List<YouzanGoodsOrderDTO> getYouzanGoodsOrderDTO()
        {
            return
                FunctionHelper.JsonDeserialization<List<YouzanGoodsOrderDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/youzan/getYouzanGoodsOrderUnDelivery"
                        )
                    );
        }
        /// <summary>
        /// 根据抖音订单号查询抖音订单明细
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public static List<DouyinOrderBarcodeMapFacadeDTO> getDouyinOrderInfoByOrderNo(String orderNo)
        {
            return
                FunctionHelper.JsonDeserialization<List<DouyinOrderBarcodeMapFacadeDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/douyin/getDouyinOrderInfoByOrderNo?orderNo=" + orderNo
                        )
                    );
        }

        /// <summary>
        /// 扫码完成订单标记
        /// </summary>
        /// <param name="barcode"></param>
        /// <param name="douyinOrderBarcodeMapFacadeDTOS"></param>
        /// <returns></returns>
        public static DouyinOrderBarcodeMapQueryFacadeDTO checkDouyinOrderBarcodeMapFacadeDTO(String barcode, List<DouyinOrderBarcodeMapFacadeDTO> douyinOrderBarcodeMapFacadeDTOS)
        {
            return
                FunctionHelper.JsonDeserialization<DouyinOrderBarcodeMapQueryFacadeDTO>(
                    RestCall.PostHttp(
                        URL.接口url1 + "/douyin/checkDouyinOrderBarcodeMapFacadeDTO?barcode=" + barcode,
                        FunctionHelper.JsonSerialization(douyinOrderBarcodeMapFacadeDTOS)
                        )
                    );
        }
     /// <summary>
     /// 查询保存
     /// </summary>
     /// <param name="barcode"></param>
     /// <param name="douyinOrderBarcodeMapFacadeDTOs"></param>
     /// <returns></returns>
        public static DouyinBarcodeQueryViewModel douyinBarcodeQueryViewDTOs(String orderNo, List<DouyinBarcodeQueryViewDTO> douyinBarcodeQueryViewDTOs)
        {
            return
                FunctionHelper.JsonDeserialization<DouyinBarcodeQueryViewModel>(
                    RestCall.PostHttp(
                        URL.接口url1 + "/douyin/saveDouyinOrderBarcodeMap?orderNo=" + orderNo,
                        FunctionHelper.JsonSerialization(douyinBarcodeQueryViewDTOs)
                        )
                    );
        }
        /// <summary>
        /// 删除成衣码
        /// </summary>
        /// <param name="barcode"></param>
        /// <param name="douyinOrderBarcodeMapFacadeDTOS"></param>
        /// <returns></returns>
        public static DouyinOrderBarcodeMapQueryFacadeDTO douyindeleteBarcodeFromOrder(String barcode, List<DouyinOrderBarcodeMapFacadeDTO> douyinOrderBarcodeMapFacadeDTOS)
        {
            return
                FunctionHelper.JsonDeserialization<DouyinOrderBarcodeMapQueryFacadeDTO>(
                    RestCall.PostHttp(
                        URL.接口url1 + "/douyin/deleteBarcodeFromOrder?barcode=" + barcode,
                        FunctionHelper.JsonSerialization(douyinOrderBarcodeMapFacadeDTOS)
                        )
                    );
        }
    }

    public class CustomerBaseInfoDTO
    {
        public String mobile { get; set; } //电话号
        public String customerName { get; set; }//客户名
        public String addressProvince { get; set; }//省
        public String addressCity { get; set; }//市
        public String addressDistrict { get; set; }//县
        public String addressDetail { get; set; }//具体地址
        public int quantity { get; set; }//总数量
        public int subordernoCount { get; set; }//订单数
        public Double payable { get; set; }//总金额
        public DateTime minOrderdate { get; set; }//最早下单时间
        public DateTime maxOrderdate { get; set; }//最晚下单时间
        public int datestrCount { get; set; }//活跃天数
        public CustomerBaseInfoDTO()
        {

        }
    }

    public class ViewSemiCheckExceptionDao
    {
        public String id { get; set; } //
        public String styleNameCn { get; set; }//
        public String materialNo { get; set; }//
        public DateTime minOrderDate { get; set; }//
        public DateTime maxOrderDate { get; set; }//
        public int orderQuantity { get; set; }//
        public int washingmarkQuantity { get; set; }//
        public int semiCheckQuantity { get; set; }//
        public String stepName { get; set; }//
        public int stockInQuantity { get; set; }//
        public String styleCode { get; set; }//
        public String detailUrl { get; set; }//
        public Double salePrice { get; set; }
        public Image pic { get; set; }


        public void getPic()
        {
            try
            {
                this.pic = FileService.GetImageByUrl(this.detailUrl);
            }
            catch { }
        }

        public class YouzanGoodsOrderDTO
        {
            public String styleCode { get; set; } //款号
            public String materialCode { get; set; } //面料号
            public String imageUrl { get; set; } //图片地址
            public String sizeCd { get; set; } //尺码
            public String memo { get; set; } //买家备注
            public String shopMemo { get; set; } //卖家备注
            public String receipt { get; set; } //收货人
            public String mobile { get; set; } //收货人手机号
            public String province { get; set; } //收货人省份
            public String city { get; set; } //收货人城市
            public String district { get; set; } //收货人地区
            public String addressDetail { get; set; } //收货人详细地址
            public DateTime orderDate { get; set; } //交易成功时间
            public Image pic { get; set; } //图片
            public String quantity { get; set; }  //商品数量

            public YouzanGoodsOrderDTO(String styleCode, String materialCode, String imageUrl, String sizeCd, String memo, String shopMemo, String quantity, String receipt, String mobile, String province, String city, String district, String addressDetail, DateTime orderDate)
            {
                this.styleCode = styleCode;
                this.materialCode = materialCode;
                this.imageUrl = imageUrl;
                this.sizeCd = sizeCd;
                this.memo = memo;
                this.shopMemo = shopMemo;
                this.quantity = quantity;
                this.receipt = receipt;
                this.mobile = mobile;
                this.province = province;
                this.city = city;
                this.district = district;
                this.addressDetail = addressDetail;
                this.orderDate = orderDate;
                this.getPic();
            }
            public void getPic()
            {
                try
                {
                    this.pic = FileService.GetImageByUrl(this.imageUrl);
                }
                catch { }
            }

            public YouzanGoodsOrderDTO buildAddress()
            {
                this.addressDetail = this.addressDetail
                               .Replace(this.province, "")
                               .Replace(this.city, "")
                               .Replace(this.district, "")
                               .Replace("，", "");
                return this;
            }

            public YouzanGoodsOrderDTO build(Dictionary<String, String> dict)
            {
                if (dict.ContainsKey(this.mobile))
                    this.receipt = dict[this.mobile];
                return this;
            }

        }

        public class xxx
        {
            public String mobile { get; set; }
            public String name { get; set; }

            public xxx(String mobile, String name)
            {
                this.mobile = mobile;
                this.name = name;
            }
        }
        public class DouyinOrderBarcodeMapFacadeDTO
        {
            public String suborderNo { get; set; }
            public String inventoryNo { get; set; }
            public String styleCode { get; set; }
            public String materialCode { get; set; }
            public String styleSizeCd { get; set; }
            public int quantity { get; set; }
            public DateTime orderDate { get; set; }
            public Double unitPrice { get; set; }
            public Double payable { get; set; }
            public String orderStatus { get; set; }
            public String customerName { get; set; }
            public String mobile { get; set; }
            public String addressProvince { get; set; }
            public String addressCity { get; set; }
            public String addressDistrict { get; set; }
            public String addressDetail { get; set; }
            public List<DouyinOrderBarcodeMapDTO> douyinOrderBarcodeMapDTOList { get; set; } = new List<DouyinOrderBarcodeMapDTO>();
            public Dictionary<String, DouyinOrderBarcodeMapDTO> douyinOrderBarcodeMapDTOMap { get; set; } = new Dictionary<String, DouyinOrderBarcodeMapDTO>();
            public DouyinOrderBarcodeMapFacadeDTO(String suborderNo, String inventoryNo, String styleCode, String materialCode, String styleSizeCd, int quantity, DateTime orderDate, Double unitPrice, Double payable, String orderStatus, String customerName, String mobile, String addressProvince, String addressCity, String addressDistrict, String addressDetail)
            {
                this.suborderNo = suborderNo;
                this.inventoryNo = inventoryNo;
                this.styleCode = styleCode;
                this.materialCode = materialCode;
                this.styleSizeCd = styleSizeCd;
                this.quantity = quantity;
                this.orderDate = orderDate;
                this.unitPrice = unitPrice;
                this.payable = payable;
                this.orderStatus = orderStatus;
                this.customerName = customerName;
                this.mobile = mobile;
                this.addressProvince = addressProvince;
                this.addressCity = addressCity;
                this.mobile = mobile;
                this.addressDistrict = addressDistrict;
                this.addressDetail = addressDetail;
            }
        }
        public class DouyinOrderBarcodeMapDTO
        {
            public String barcode { get; set; }
            public String styleCode { get; set; }
            public String materailCode { get; set; }
            public String sizeCd { get; set; }
            public DouyinOrderBarcodeMapDTO(String barcode, String styleCode, String materailCode, String sizeCd)
            {
                this.barcode = barcode;
                this.styleCode = styleCode;
                this.materailCode = materailCode;
                this.sizeCd = sizeCd;
            }
        }

        public class DouyinOrderBarcodeMapQueryFacadeDTO
        {
            internal object barcode;

            public List<DouyinOrderBarcodeMapFacadeDTO> douyinOrderBarcodeMapFacadeDTOS { get; set; } = new List<DouyinOrderBarcodeMapFacadeDTO>();
            public Boolean success { get; set; }
            public String errorMessage { get; set; }
            public DouyinOrderBarcodeMapQueryFacadeDTO()
            {

            }
        }

        /// <summary>
        /// 数据展示视图
        /// </summary>
        public class DouyinBarcodeQueryViewDTO {
            public String suborderNo { get; set; }
            public String inventoryNo { get; set; }
            public String orderStatus { get; set; }
            public String styleCode { get; set; }
            public String materialCode { get; set; }
            public String styleSizeCd { get; set; }
            public int quantity { get; set; }
            public DateTime orderDate { get; set; }
            public Double unitPrice { get; set; }
            public Double payable { get; set; }
            public String barcode { get; set; }

            public DouyinBarcodeQueryViewDTO(DouyinOrderBarcodeMapFacadeDTO orderBarcodeMapFacadeDTO,String barcode) {
                this.suborderNo = orderBarcodeMapFacadeDTO.suborderNo;
                this.inventoryNo = orderBarcodeMapFacadeDTO.inventoryNo;
                this.orderStatus = orderBarcodeMapFacadeDTO.orderStatus;
                this.styleCode = orderBarcodeMapFacadeDTO.styleCode;
                this.materialCode = orderBarcodeMapFacadeDTO.materialCode;
                this.styleSizeCd = orderBarcodeMapFacadeDTO.styleSizeCd;
                this.quantity = orderBarcodeMapFacadeDTO.quantity;
                this.orderDate = orderBarcodeMapFacadeDTO.orderDate;
                this.unitPrice = orderBarcodeMapFacadeDTO.unitPrice;
                this.payable = orderBarcodeMapFacadeDTO.payable;
                this.barcode = barcode;
            }

        }

        public class DouyinBarcodeQueryViewModel{
            public List<DouyinBarcodeQueryViewDTO> douyinBarcodeQueryViewDTOs { get; set; }
            public DouyinBarcodeQueryViewModel(List<DouyinOrderBarcodeMapFacadeDTO> douyinOrderBarcodeMapFacadeDTOs) {
                this.douyinBarcodeQueryViewDTOs = new List<DouyinBarcodeQueryViewDTO>();
                foreach (DouyinOrderBarcodeMapFacadeDTO orderBarcodeMapFacadeDTO in douyinOrderBarcodeMapFacadeDTOs)
                {
                    for (int i = 0; i < orderBarcodeMapFacadeDTO.quantity; i++) {
                        if(i< orderBarcodeMapFacadeDTO.douyinOrderBarcodeMapDTOList.Count()) 
                            this.douyinBarcodeQueryViewDTOs.Add(new DouyinBarcodeQueryViewDTO(orderBarcodeMapFacadeDTO, orderBarcodeMapFacadeDTO.douyinOrderBarcodeMapDTOList[i].barcode));
                        else
                            this.douyinBarcodeQueryViewDTOs.Add(new DouyinBarcodeQueryViewDTO(orderBarcodeMapFacadeDTO, ""));
                    }
                }
            }
            
        }
    }
}

